import { createStore } from 'vuex'
// 引入持久化
import createPersistedState from 'vuex-persistedstate'

const store = createStore({
  state() {
    return {
      count: 0,
      status: '正常',
    }
  },
  getters: {
    getStatus(state) {
      console.log('getStatus:', state)
      return state.status
    },
  },
  mutations: {
    addCount(state) {
      console.log('state:', state)
      state.count++
    },
  },
  //   持久化存储
  plugins: [
    createPersistedState({
      key: 'vuex', // 存储是的名字
      // 也可以是sessionstorage
      storage: window.localStorage,
      //   指定存储的变量
      //   paths: ['count'],
    }),
  ],
})

export default store
